package com.jhy.javacase.io;

import java.io.*;

/**
 * @author jhy
 * @ClassName DataInputOutputCase.java
 * @Description 使用DataInput和DataOutput读写二进制数据
 * @createTime 2022年02月28日 12:26:00
 */
public class DataInputOutputCase {

    public static void main(String[] args) throws IOException {
        //二进制输出流DataOutputStream
        DataOutputStream outputStream = new DataOutputStream(new FileOutputStream("E:\\java项目\\Guava学习\\guava-case\\guava-case\\src\\main\\resources\\io\\targetFile.txt"));
        outputStream.writeByte(100);
        outputStream.writeShort(200);
        outputStream.writeInt(300);
        outputStream.writeLong(400L);
        outputStream.writeFloat(456F);
        outputStream.writeDouble(99.99);

        //二进制输入流DataInputStream
        DataInputStream inputStream = new DataInputStream(new FileInputStream("E:\\java项目\\Guava学习\\guava-case\\guava-case\\src\\main\\resources\\io\\targetFile.txt"));
        System.out.println(inputStream.readByte());
        System.out.println(inputStream.readShort());
        System.out.println(inputStream.readInt());
        System.out.println(inputStream.readLong());
        System.out.println(inputStream.readFloat());
        System.out.println(inputStream.readDouble());
        //关闭流
        outputStream.close();
        inputStream.close();
    }
}
